package com.dong.abstractFactoryMode.service.factory;



import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author DongJiaQi
 * @create 2022/12/20 14:07
 * @Description: 代理类实现
 */
public class JDKInvocationHandler  implements InvocationHandler {

    private ICacheAdapter cacheAdapter;

    public JDKInvocationHandler(ICacheAdapter cacheAdapter) {
        this.cacheAdapter = cacheAdapter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Class<?>[] parameterTypes = method.getParameterTypes();
        String name = method.getName();
        return ICacheAdapter.class.getMethod(name, parameterTypes).invoke(cacheAdapter,args);
    }
}
